package com.jing.cloud.service.buddy.method;

import com.jing.cloud.service.buddy.constant.BuddyConstant;
import com.jing.cloud.service.buddy.constant.BuddyErrCode;
import com.jing.cloud.service.buddy.helper.BuddyHelper;
import com.jing.cloud.service.buddy.method.param.AddBuddyBean;
import com.jing.cloud.service.method.AbstractMethod;
import com.jing.cloud.service.method.Method;
import com.jing.cloud.service.Res;
import com.jing.cloud.util.RspUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by 29017 on 2017/9/19.
 */
@Component
public class AddBuddy extends AbstractMethod<AddBuddyBean> implements Method<AddBuddyBean> {

    @Autowired
    BuddyHelper buddyHelper;

    @Override
    public Res call(AddBuddyBean addBuddyBean) throws Exception {
        if (addBuddyBean.getBuddyMode() == BuddyConstant.BUDDY_MODE_ONE_WAY) {
            return buddyHelper.addBuddyOneWay(getUserId(), addBuddyBean.getTargetId());
        } else if (addBuddyBean.getBuddyMode() == BuddyConstant.BUDDY_MODE_TOW_WAY) {
            // TODO: 2017/9/19 这里直接互加
            buddyHelper.addBuddyOneWay(getUserId(), addBuddyBean.getTargetId());
            buddyHelper.addBuddyOneWay(addBuddyBean.getTargetId(), getUserId());
            return RspUtil.success();
        } else {
            return RspUtil.error(BuddyErrCode.BUDDY_MODE_INVALID);
        }
    }
}
